#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<cstring>
#include<vector>

using namespace std;

class Solution {
    int f[1010];
public:
    int combinationSum4(vector<int>& nums, int target) {
        memset(f, 0, sizeof f);
        f[0] = 1;

        for (int i = 1; i <= target; i++)
            for (int j = 0; j < nums.size(); j++)
                if (nums[j] <= i && f[i - nums[j]] < INT_MAX - f[i])
                    f[i] += f[i - nums[j]];

        return f[target];
    }
};